package com.engine.cese.duss.srm.util;

import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @Title: Ecology9
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-03-29
 * @Description: 采购需求池数据插入到采购任务池
 * @ModifyLog:
 **/

public class DataUtil {
    //物料采购需求池数据插入到物料采购任务池
    public static boolean wlneedTowltaskPool(String userid, String billid) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        boolean flag = true;
        baseBean.writeLog( "wlneedTowltaskPool-----------------" + billid );
        try {
            String cglx = "0";
            RecordSet rs1 = new RecordSet();
            String rwbh = GenUtil.generTaskCode( cglx );//任务编号
            String cgxqTable = GenUtil.getCgxqTableType( cglx );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            String comFields = "xqly,xqdjr,xqdw,sfjcxq,xqrq,xqlx,xmmc,xmbh,xmxz,wllb,\n" +
                    "ppfw,ygje,spdhrq,cgqx,sfbq,fj,xqdh,xqbh,bgdh,bgbh,\n" +
                    "jbgsl,xqfl,jcdh,htdh,jhdbjcsj,cgms,cgy,cgfs,pbfs,shdz,\n" +
                    "pid,bz,bmid,fbid,bglsh,xmxzid,xqdwid,xqdwmc,xmid";
            //插入主表
            String sql = "select " + comFields + ",zcdbjcrq,nd from " + cgxqTable + " where id=?";
            rs.executeQuery( sql, billid );
            if (rs.next()) {
                String xqly = Util.null2String( rs.getString( "xqly" ) );//需求来源
                String xqdjr = Util.null2String( rs.getString( "xqdjr" ) );//需求对接人
                String xqdw = Util.null2String( rs.getString( "xqdw" ) );//需求单位ID
                String sfjcxq = Util.null2String( rs.getString( "sfjcxq" ) );//是否集采需求
                String xqrq = Util.null2String( rs.getString( "xqrq" ) );//需求日期
                String xqlx = Util.null2String( rs.getString( "xqlx" ) );//需求类型
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                String xmbh = Util.null2String( rs.getString( "xmbh" ) );//项目编号
                String xmxz = Util.null2String( rs.getString( "xmxz" ) );//项目性质
                String wllb = Util.null2String( rs.getString( "wllb" ) );//物料类别
                String ppfw = Util.null2String( rs.getString( "ppfw" ) );//品牌范围
                String ygje = Util.null2String( rs.getString( "ygje" ) );//预估金额
                String spdhrq = Util.null2String( rs.getString( "spdhrq" ) );//首批到货日期
                String cgqx = Util.null2String( rs.getString( "cgqx" ) );//采购权限
                String sfbq = Util.null2String( rs.getString( "sfbq" ) );//是否标前
                String fj = Util.null2String( rs.getString( "fj" ) );//附件
                String xqdh = Util.null2String( rs.getString( "xqdh" ) );//需求单号
                String xqbh = Util.null2String( rs.getString( "xqbh" ) );//需求包号
                String bgdh = Util.null2String( rs.getString( "bgdh" ) );//变更单号
                String bgbh = Util.null2String( rs.getString( "bgbh" ) );//变更包号
                String jbgsl = Util.null2String( rs.getString( "jbgsl" ) );//仅变更数量
                String xqfl = Util.null2String( rs.getString( "xqfl" ) );//需求分类
                String jcdh = Util.null2String( rs.getString( "jcdh" ) );//决策单号
                String htdh = Util.null2String( rs.getString( "htdh" ) );//合同单号
                String jhdbjcsj = Util.null2String( rs.getString( "jhdbjcsj" ) );//计划定标决策时间
                String cgms = Util.null2String( rs.getString( "cgms" ) );//采购模式
                String cgy = Util.null2String( rs.getString( "cgy" ) );//采购员
                String cgfs = Util.null2String( rs.getString( "cgfs" ) );//采购方式
                String pbfs = Util.null2String( rs.getString( "pbfs" ) );//评标方式
                String shdz = Util.null2String( rs.getString( "shdz" ) );//收货地址
                String pid = Util.null2String( rs.getString( "pid" ) );//PID
                String bz = Util.null2String( rs.getString( "bz" ) );//备注
                String bmid = Util.null2String( rs.getString( "bmid" ) );//部门ID
                String fbid = Util.null2String( rs.getString( "fbid" ) );//分部id
                String bglsh = Util.null2String( rs.getString( "bglsh" ) );//变更流水号
                String xmxzid = Util.null2String( rs.getString( "xmxzid" ) );//项目性质ID
                String xqdwid = Util.null2String( rs.getString( "xqdwid" ) );//需求单位ID-树
                String xqdwmc = Util.null2String( rs.getString( "xqdwmc" ) );//需求单位名称
                String xmid = Util.null2String( rs.getString( "xmid" ) );//项目ID
                String zcdbjcrq = Util.null2String( rs.getString( "zcdbjcrq" ) );//最迟定标决策日期
                String nd = Util.null2String( rs.getString( "nd" ) );//年度
                String rwzt = "0";//任务状态
                String cfdid = "";
                String formmodeid = GenUtil.getFormmodeId( cglx );
                String modedatacreatertype = "0";
                String modedatacreater = userid;
                String modedatacreatedate = DateUtil.getCurrentDate();
                String fullDate = DateUtil.getFullDate();
                String modedatacreatetime = fullDate.substring( 11, 19 );
                String fields = comFields + ",rwzt,xqdid,rwbh,zcdbjcsj,cfdid,nd,cglx," +
                        "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime";
                String values = "values(" +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?)";
                String sql1 = "insert into " + cgrwTable + " (" + fields + ") " + values;
                rs.writeLog( sql1 );
                Object[] params = {xqly, xqdjr, xqdw, sfjcxq, xqrq, xqlx, xmmc, xmbh, xmxz, wllb,
                        ppfw, ygje, spdhrq, cgqx, sfbq, fj, xqdh, xqbh, bgdh, bgbh,
                        jbgsl, xqfl, jcdh, htdh, jhdbjcsj, cgms, cgy, cgfs, pbfs, shdz,
                        pid, bz, bmid, fbid, bglsh, xmxzid, xqdwid, xqdwmc, xmid,
                        rwzt, billid, rwbh, zcdbjcrq, cfdid, nd, cglx,
                        formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime};
                if (rs.executeUpdate( sql1, params )) {
                    //插入明细表
                    String mainid = GenUtil.getRwbh2Id( rwbh, cglx );
                    GenUtil.getNewModeRight( cgy, formmodeid, mainid );
                    String comFieldDt1 = "wlbm,wlmc,cms,xlh,xlbz,dw,sl,fzdw,\n" +
                            " fzsl,cgsl,sysl,fb,zfb,fbbh,zfbbh,zfbid,wlid";
                    String sql2 = "select wm_concat(id) as id,wlbm,wlmc,cms,xlh,xlbz,dw,sum(sl) as sl,fzdw," +
                            "sum(fzsl) as fzsl,sum(cgsl) as cgsl,sum(sysl) as sysl,fbbh,zfbbh,zfbid,wlid\n" +
                            "from " + cgxqTable + "_dt1 where mainid=? and nvl(cfbj,0)=0\n" +
                            "group by wlbm,wlmc,cms,xlh,xlbz,dw,fzdw,fbbh,zfbbh,zfbid,wlid";
                    rs1.executeQuery( sql2, billid );
                    rs1.writeLog( sql2, billid );
                    int counts = rs1.getColCounts();
                    int count = 0;
                    while (rs1.next()) {
                        String id = Util.null2String( rs1.getString( "id" ) );//物料名称
                        String wlbm = Util.null2String( rs1.getString( "wlbm" ) );//物料编码
                        String wlmc = Util.null2String( rs1.getString( "wlmc" ) );//物料名称
                        String cms = Util.null2String( rs1.getString( "cms" ) );//长描述
                        String xlh = Util.null2String( rs1.getString( "xlh" ) );//序列号
                        String xlbz = Util.null2String( rs1.getString( "xlbz" ) );//序列备注
                        String dw = Util.null2String( rs1.getString( "dw" ) );//单位
                        String sl = Util.null2String( rs1.getString( "sl" ) );//数量
                        String fzdw = Util.null2String( rs1.getString( "fzdw" ) );//辅助单位
                        String fzsl = Util.null2String( rs1.getString( "fzsl" ) );//辅助数量
                        String cgsl = Util.null2String( rs1.getString( "cgsl" ) );//采购数量
                        String sysl = Util.null2String( rs1.getString( "sysl" ) );//剩余数量
                        String fb = Util.null2String( rs1.getString( "fb" ) );//分布
                        String zfb = Util.null2String( rs1.getString( "zfb" ) );//子分布
                        String fbbh = Util.null2String( rs1.getString( "fbbh" ) );//分部编号
                        String zfbbh = Util.null2String( rs1.getString( "zfbbh" ) );//子分部编号
                        String zfbid = Util.null2String( rs1.getString( "zfbid" ) );//子分部id
                        String wlid = Util.null2String( rs1.getString( "wlid" ) );//物料id
                        String sql3 = "insert into " + cgrwTable + "_dt1 (mainid," + comFieldDt1 + ",xqmxid) " +
                                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, wlbm, wlmc, cms, xlh, xlbz, dw, sl, fzdw,
                                fzsl, cgsl, sysl, fb, zfb, fbbh, zfbbh, zfbid, wlid, id};
                        if (rs1.executeUpdate( sql3, params1 )) {
                            count++;
                        }
                        //更新物料采购需求池的勾选拆分
                        rs1.executeUpdate( "update " + cgxqTable + "_dt1 set cfbj=1 where id in (" + id + ")" );
                    }
                    if ((counts - count) > 0) {
                        flag = false;
                    }
                }
            }
            //更新需求池当前阶段、剩余招标周期、偏差状态、偏差时间
            rs.executeQuery( "select xqrq,zcdbjcrq from " + cgxqTable + " where id=?", billid );
            rs.next();
            String xqrq = Util.null2String( rs.getString( "xqrq" ) );
            String zcdbjcrq = Util.null2String( rs.getString( "zcdbjcrq" ) );
            if (!"".equals( zcdbjcrq )) {
                long syzbzq = getDays( zcdbjcrq );
                long pcrq = getDays( xqrq ) + 2;
                if (syzbzq <= 0) {
                    rs.executeUpdate( "update uf_cgxq_wl t set t.pczt=0,t.syzbzq=?,t.dqjd=0,t.pcsj=? where t.id=?", syzbzq, pcrq, billid );
                } else if (syzbzq <= 7) {
                    rs.executeUpdate( "update uf_cgxq_wl t set t.pczt=1,t.syzbzq=?,t.dqjd=0,t.pcsj=? where t.id=?", syzbzq, pcrq, billid );
                } else if (syzbzq > 7) {
                    rs.executeUpdate( "update uf_cgxq_wl t set t.pczt=2,t.syzbzq=?,t.dqjd=0,t.pcsj=? where t.id=?", syzbzq, pcrq, billid );
                }
            }
        } catch (Exception e) {
           baseBean.writeLog( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return flag;
    }

    //工程采购需求池数据插入到工程采购任务池
    public static boolean gcneedTogctaskPool(String userid, String billid) {
        boolean flag = true;
        BaseBean baseBean = new BaseBean();
        RecordSet rs = new RecordSet();
        baseBean.writeLog( "gcneedTogctaskPool-----------------" + billid );
        try {
            String cglx = "1";
            RecordSet rs1 = new RecordSet();
            String rwbh = GenUtil.generTaskCode( cglx );//任务编号
            String cgxqTable = GenUtil.getCgxqTableType( cglx );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            String comFields = "xmid,xqly,xqdjr,xqdw,sfjcxq,xqrq,xqlx,xmmc,xmbh,xmxz,\n" +
                    "fbbd,fblx,fbnrms,yjjcrq,yjtcsj,ygldlxq,tjfbs,ygje,sfbq,gyssl,\n" +
                    "fj,xqdh,xqbh,bgdh,bgbh,htdh,fplx,xqfl,jhdbjcsj,cgy,\n" +
                    "cgfs,pbfs,bz,fbzyej,pid,bmid,fbid,ppfw,bglsh,xmxzid,\n" +
                    "xqdwid,xqdwmc,jbgsl,cgqx,xmdd";
            //插入主表
            String sql = "select " + comFields + ",zcdbjcrq,nd,srmjcdh,fbzyyj from " + cgxqTable + " where id=?";
            //插入主表
            rs.executeQuery( sql, billid );
            if (rs.next()) {
                String xmid = Util.null2String( rs.getString( "xmid" ) );//项目ID
                String xqly = Util.null2String( rs.getString( "xqly" ) );//需求来源
                String xqdjr = Util.null2String( rs.getString( "xqdjr" ) );//需求对接人
                String xqdw = Util.null2String( rs.getString( "xqdw" ) );//需求单位ID
                String sfjcxq = Util.null2String( rs.getString( "sfjcxq" ) );//是否集采需求
                String xqrq = Util.null2String( rs.getString( "xqrq" ) );//需求日期
                String xqlx = Util.null2String( rs.getString( "xqlx" ) );//需求类型
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                String xmbh = Util.null2String( rs.getString( "xmbh" ) );//项目编号
                String xmxz = Util.null2String( rs.getString( "xmxz" ) );//项目性质
                String fbbd = Util.null2String( rs.getString( "fbbd" ) );//分包标段
                String fblx = Util.null2String( rs.getString( "fblx" ) );//分包类型
                String fbnrms = Util.null2String( rs.getString( "fbnrms" ) );//分包内容描述
                String yjjcrq = Util.null2String( rs.getString( "yjjcrq" ) );//预计进场日期
                String yjtcsj = Util.null2String( rs.getString( "yjtcsj" ) );//预计退场时间
                String ygldlxq = Util.null2String( rs.getString( "ygldlxq" ) );//预估劳动力需求
                String tjfbs = Util.null2String( rs.getString( "tjfbs" ) );//推荐分包商
                String ygje = Util.null2String( rs.getString( "ygje" ) );//预估金额
                String sfbq = Util.null2String( rs.getString( "sfbq" ) );//是否标前
                String gyssl = Util.null2String( rs.getString( "gyssl" ) );//供应商数量
                String fj = Util.null2String( rs.getString( "fj" ) );//附件
                String xqdh = Util.null2String( rs.getString( "xqdh" ) );//需求单号
                String xqbh = Util.null2String( rs.getString( "xqbh" ) );//需求包号
                String bgdh = Util.null2String( rs.getString( "bgdh" ) );//变更单号
                String bgbh = Util.null2String( rs.getString( "bgbh" ) );//变更包号
                String htdh = Util.null2String( rs.getString( "htdh" ) );//合同单号
                String fplx = Util.null2String( rs.getString( "fplx" ) );//分配类型
                String xqfl = Util.null2String( rs.getString( "xqfl" ) );//需求分类
                String jhdbjcsj = Util.null2String( rs.getString( "jhdbjcsj" ) );//计划定标决策时间
                String cgy = Util.null2String( rs.getString( "cgy" ) );//采购员
                String cgfs = Util.null2String( rs.getString( "cgfs" ) );//采购方式
                String pbfs = Util.null2String( rs.getString( "pbfs" ) );//评标方式
                String bz = Util.null2String( rs.getString( "bz" ) );//备注
                String fbzyej = Util.null2String( rs.getString( "fbzyej" ) );//分包专业（二级）
                String pid = Util.null2String( rs.getString( "pid" ) );//PID
                String bmid = Util.null2String( rs.getString( "bmid" ) );//部门ID
                String fbid = Util.null2String( rs.getString( "fbid" ) );//分部id
                String ppfw = Util.null2String( rs.getString( "ppfw" ) );//品牌范围
                String bglsh = Util.null2String( rs.getString( "bglsh" ) );//变更流水号
                String xmxzid = Util.null2String( rs.getString( "xmxzid" ) );//项目性质ID
                String xqdwid = Util.null2String( rs.getString( "xqdwid" ) );//需求单位ID-树
                String xqdwmc = Util.null2String( rs.getString( "xqdwmc" ) );//需求单位名称
                String jbgsl = Util.null2String( rs.getString( "jbgsl" ) );//仅变更数量
                String cgqx = Util.null2String( rs.getString( "cgqx" ) );//采购权限
                String xmdd = Util.null2String( rs.getString( "xmdd" ) );//项目地点
                String zcdbjcrq = Util.null2String( rs.getString( "zcdbjcrq" ) );//最迟定标决策日期
                String nd = Util.null2String( rs.getString( "nd" ) );//年度
                String srmjcdh = Util.null2String( rs.getString( "srmjcdh" ) );//决策单号
                String fbzyyj = Util.null2String( rs.getString( "fbzyyj" ) );//分包专业（一级）
                String rwzt = "0";//任务状态
                String cfdid = "";
                String formmodeid = GenUtil.getFormmodeId( cglx );
                String modedatacreatertype = "0";
                String modedatacreater = userid;
                String modedatacreatedate = DateUtil.getCurrentDate();
                String fullDate = DateUtil.getFullDate();
                String modedatacreatetime = fullDate.substring( 11, 19 );
                String fields = comFields + ",zcdbjcsj,xqdid,cfdid,rwbh,nd,jcdh,fbzyyj,rwzt,cglx," +
                        "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime";
                String values = "values(" +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                String sql1 = "insert into " + cgrwTable + " (" + fields + ") " + values;
                rs.writeLog( sql1 );
                Object[] params = {xmid, xqly, xqdjr, xqdw, sfjcxq, xqrq, xqlx, xmmc, xmbh, xmxz,
                        fbbd, fblx, fbnrms, yjjcrq, yjtcsj, ygldlxq, tjfbs, ygje, sfbq, gyssl,
                        fj, xqdh, xqbh, bgdh, bgbh, htdh, fplx, xqfl, jhdbjcsj, cgy,
                        cgfs, pbfs, bz, fbzyej, pid, bmid, fbid, ppfw, bglsh, xmxzid,
                        xqdwid, xqdwmc, jbgsl, cgqx, xmdd, zcdbjcrq, billid, cfdid, rwbh, nd, srmjcdh, fbzyyj, rwzt, cglx,
                        formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime};
                if (rs.executeUpdate( sql1, params )) {
                    //插入明细表
                    String comFieldDt1 = "sl,dw,dwgc,zdwgc,fbgc,zfbgc,qdbh,qdmc,cms,gznr,jsgz,bz";
                    String mainid = GenUtil.getRwbh2Id( rwbh, cglx );
                    GenUtil.getNewModeRight( cgy, formmodeid, mainid );
                    String sql2 = "select id," + comFieldDt1 + " from " + cgxqTable + "_dt1 where mainid=?";
                    rs1.executeQuery( sql2, billid );
                    rs1.writeLog( sql2, billid );
                    int count1s = rs1.getColCounts();
                    int count1 = 0;
                    while (rs1.next()) {
                        String xqmxid = Util.null2String( rs1.getString( "id" ) );//id
                        String sl = Util.null2String( rs1.getString( "sl" ) );//分部
                        String dw = Util.null2String( rs1.getString( "dw" ) );//子分部
                        String dwgc = Util.null2String( rs1.getString( "dwgc" ) );//物料编码
                        String zdwgc = Util.null2String( rs1.getString( "zdwgc" ) );//物料名称
                        String fbgc = Util.null2String( rs1.getString( "fbgc" ) );//长描述
                        String zfbgc = Util.null2String( rs1.getString( "zfbgc" ) );//序列号
                        String qdbh = Util.null2String( rs1.getString( "qdbh" ) );//序列备注
                        String qdmc = Util.null2String( rs1.getString( "qdmc" ) );//单位
                        String cms = Util.null2String( rs1.getString( "cms" ) );//数量
                        String gznr = Util.null2String( rs1.getString( "gznr" ) );//辅助单位
                        String jsgz = Util.null2String( rs1.getString( "jsgz" ) );//辅助数量
                        String bz1 = Util.null2String( rs1.getString( "bz" ) );//采购数量
                        String sql3 = "insert into " + cgrwTable + "_dt1 (mainid," + comFieldDt1 + ",xqmxid)" +
                                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, sl, dw, dwgc, zdwgc, fbgc, zfbgc, qdbh, qdmc, cms, gznr, jsgz, bz1, xqmxid};
                        if(rs1.executeUpdate( sql3, params1 )){
                            count1++;
                        }
                    }
                    String sql3 = "select xlh,xlbz,fzdw,wlbm,wlmc,cms,jbdw,jbsl," +
                            "cblx,sfjg,wj,fzsl from " + cgxqTable + "_dt2 where mainid=?";
                    rs1.executeQuery( sql3, billid );
                    rs1.writeLog( sql3,billid );
                    int count2s = rs1.getColCounts();
                    int count2 = 0;
                    while (rs1.next()) {
                        String xlh = Util.null2String( rs1.getString( "xlh" ) );//id
                        String xlbz = Util.null2String( rs1.getString( "xlbz" ) );//id
                        String fzdw = Util.null2String( rs1.getString( "fzdw" ) );//id
                        String wlbm = Util.null2String( rs1.getString( "wlbm" ) );//id
                        String wlmc = Util.null2String( rs1.getString( "wlmc" ) );//id
                        String cms = Util.null2String( rs1.getString( "cms" ) );//id
                        String jbdw = Util.null2String( rs1.getString( "jbdw" ) );//id
                        String jbsl = Util.null2String( rs1.getString( "jbsl" ) );//id
                        String cblx = Util.null2String( rs1.getString( "cblx" ) );//id
                        String sfjg = Util.null2String( rs1.getString( "sfjg" ) );//id
                        String xqwj = Util.null2String( rs1.getString( "wj" ) );//id
                        String fzsl = Util.null2String( rs1.getString( "fzsl" ) );//id
                        String sql4 = "insert into " + cgrwTable + "_dt2 (mainid,xlh,xlbz,fzdw,wlbm,wlmc,cms,jbdw,jbsl," +
                                "cblx,sfjg,xqwj,fzsl) " +
                                "values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, xlh, xlbz, fzdw, wlbm, wlmc, cms, jbdw, jbsl,
                                cblx, sfjg, xqwj, fzsl};
                        if(rs1.executeUpdate( sql4, params1 )){
                            count2++;
                        }
                    }
                    if ((count1s - count1) > 0 || (count2s - count2) > 0) {
                        flag = false;
                    }
                    String sql5 = "select id,xqmxid from " + cgrwTable + "_dt1 where mainid=?";
                    rs1.executeQuery( sql5, mainid );
                    while (rs1.next()) {
                        String id = Util.null2String( rs1.getString( "id" ) );//id
                        String xqmxid = Util.null2String( rs1.getString( "xqmxid" ) );//id
                        rs1.executeUpdate( "update " + cgrwTable + "_dt2 set wj=? where xqwj=?", id, xqmxid );
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return flag;
    }

    //租赁采购需求池数据插入到租赁采购任务池
    public static boolean zlneedTozltaskPool(String userid, String billid) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        boolean flag = true;
        baseBean.writeLog( "zlneedTozltaskPool-----------------" + billid );
        try {
            String cglx = "2";
            RecordSet rs1 = new RecordSet();
            String rwbh = GenUtil.generTaskCode( cglx );//任务编号
            String cgxqTable = GenUtil.getCgxqTableType( cglx );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            //插入主表
            String conFields = "xqly,xqdjr,xqdw,sfjcxq,xqrq,xqlx,xmmc,xmbh,xmxz,ygje,\n" +
                    "zllx,cgy,sfbq,jhdbjcsj,fj,bz,xqdh,jcdh,htdh,fplx,\n" +
                    "xqfl,cgfs,pbfs,bmid,fbid,pid,xqbh,nd,xmxzid,xqdwid,\n" +
                    "xqdwmc,xmid,zlnr,zcdbjcsj,cgqx";
            String sql = "select " + conFields + " from " + cgxqTable + " where id=?";
            rs.executeQuery( sql, billid );
            if (rs.next()) {
                String xqly = Util.null2String( rs.getString( "xqly" ) );//需求来源
                String xqdjr = Util.null2String( rs.getString( "xqdjr" ) );//需求对接人
                String xqdw = Util.null2String( rs.getString( "xqdw" ) );//需求单位
                String sfjcxq = Util.null2String( rs.getString( "sfjcxq" ) );//是否集采需求
                String xqrq = Util.null2String( rs.getString( "xqrq" ) );//需求日期
                String xqlx = Util.null2String( rs.getString( "xqlx" ) );//需求类型
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                String xmbh = Util.null2String( rs.getString( "xmbh" ) );//项目编号
                String xmxz = Util.null2String( rs.getString( "xmxz" ) );//项目性质
                String ygje = Util.null2String( rs.getString( "ygje" ) );//预估金额
                String zllx = Util.null2String( rs.getString( "zllx" ) );//租赁类型
                String cgy = Util.null2String( rs.getString( "cgy" ) );//采购员
                String sfbq = Util.null2String( rs.getString( "sfbq" ) );//是否标前
                String jhdbjcsj = Util.null2String( rs.getString( "jhdbjcsj" ) );//计划定标决策时间
                String fj = Util.null2String( rs.getString( "fj" ) );//附件
                String bz = Util.null2String( rs.getString( "bz" ) );//备注
                String xqdh = Util.null2String( rs.getString( "xqdh" ) );//需求单号
                String jcdh = Util.null2String( rs.getString( "jcdh" ) );//决策单号
                String htdh = Util.null2String( rs.getString( "htdh" ) );//合同单号
                String fplx = Util.null2String( rs.getString( "fplx" ) );//分配类型
                String xqfl = Util.null2String( rs.getString( "xqfl" ) );//需求分类
                String cgfs = Util.null2String( rs.getString( "cgfs" ) );//采购方式
                String pbfs = Util.null2String( rs.getString( "pbfs" ) );//评标方式
                String bmid = Util.null2String( rs.getString( "bmid" ) );//部门ID
                String fbid = Util.null2String( rs.getString( "fbid" ) );//分部ID
                String pid = Util.null2String( rs.getString( "pid" ) );//PID
                String zlnr = Util.null2String( rs.getString( "zlnr" ) );//租赁内容
                String xqbh = Util.null2String( rs.getString( "xqbh" ) );//需求包号
                String nd = Util.null2String( rs.getString( "nd" ) );//年度
                String xmxzid = Util.null2String( rs.getString( "xmxzid" ) );//项目性质ID
                String xqdwid = Util.null2String( rs.getString( "xqdwid" ) );//需求单位ID
                String xqdwmc = Util.null2String( rs.getString( "xqdwmc" ) );//需求单位名称
                String xmid = Util.null2String( rs.getString( "xmid" ) );//项目ID
                String zcdbjcsj = Util.null2String( rs.getString( "zcdbjcsj" ) );//最迟定标决策时间
                String cgqx = Util.null2String( rs.getString( "cgqx" ) );//采购权限
                int rwzt = 0;//任务状态
                String cfdid = "";
                String formmodeid = GenUtil.getFormmodeId( cglx );
                String modedatacreatertype = "0";
                String modedatacreater = userid;
                String modedatacreatedate = DateUtil.getCurrentDate();
                String fullDate = DateUtil.getFullDate();
                String modedatacreatetime = fullDate.substring( 11, 19 );
                String fields = conFields + ",rwbh,xqdid,cfdid,rwzt,cglx," +
                        "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime";
                String values = "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?)";
                String sql1 = "insert into " + cgrwTable + " (" + fields + ") " + values;
                rs.writeLog( sql1 );
                Object[] params = {xqly, xqdjr, xqdw, sfjcxq, xqrq, xqlx, xmmc, xmbh, xmxz, ygje,
                        zllx, cgy, sfbq, jhdbjcsj, fj, bz, xqdh, jcdh, htdh, fplx,
                        xqfl, cgfs, pbfs, bmid, fbid, pid, xqbh, nd, xmxzid, xqdwid,
                        xqdwmc, xmid, zlnr, zcdbjcsj, cgqx, rwbh, billid, cfdid, rwzt, cglx,
                        formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime};
                if (rs.executeUpdate( sql1, params )) {
                    //插入明细表
                    String mainid = GenUtil.getRwbh2Id( rwbh, cglx );
                    GenUtil.getNewModeRight( cgy, formmodeid, mainid );
                    String comFieldDt1 = "mc,ggxh,dw,sl,jjdw,jjsl,qzsj,jssj,cgsl,sysl";
                    String sql2 = "select " + comFieldDt1 + ",id from " + cgxqTable + "_dt1 where mainid=? and nvl(cfbj,0)=0";
                    rs1.executeQuery( sql2, billid );
                    int counts = rs1.getColCounts();
                    int count = 0;
                    while (rs1.next()) {
                        String xqmxid = Util.null2String( rs1.getString( "id" ) );//物料名称
                        String mc = Util.null2String( rs1.getString( "mc" ) );//名称
                        String ggxh = Util.null2String( rs1.getString( "ggxh" ) );//规格型号
                        String dw = Util.null2String( rs1.getString( "dw" ) );//单位
                        String sl = Util.null2String( rs1.getString( "sl" ) );//数量
                        String jjdw = Util.null2String( rs1.getString( "jjdw" ) );//计价单位
                        String jjsl = Util.null2String( rs1.getString( "jjsl" ) );//计价数量
                        String qzsj = Util.null2String( rs1.getString( "qzsj" ) );//起租时间
                        String jssj = Util.null2String( rs1.getString( "jssj" ) );//结束时间
                        String cgsl = Util.null2String( rs1.getString( "cgsl" ) );//采购数量
                        String sysl = Util.null2String( rs1.getString( "sysl" ) );//剩余数量
                        String sql3 = "insert into " + cgrwTable + "_dt1(" +
                                "mainid," + comFieldDt1 + ",xqmxid) values (?,?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, mc, ggxh, dw, sl, jjdw, jjsl, qzsj, jssj, cgsl, sysl, xqmxid};
                        if(rs1.executeUpdate( sql3, params1 )){
                            //更新物料采购需求池的勾选拆分
                            rs1.executeUpdate( "update " + cgxqTable + "_dt1 set cfbj=1 where id=?", xqmxid );
                            count++;
                        }

                    }
                    if((counts-count)>0){
                        flag = false;
                    }
                }
            }

        } catch (Exception e) {
            baseBean.writeLog( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return flag;
    }

    //运输采购需求池数据插入到运输采购任务池
    public static boolean ysneedToystaskPool(String userid, String billid) {
        boolean flag = true;
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog( "ysneedToystaskPool-----------------" + billid );
        try {
            String cglx = "3";
            RecordSet rs1 = new RecordSet();
            String rwbh = GenUtil.generTaskCode( cglx );//任务编号
            String cgxqTable = GenUtil.getCgxqTableType( cglx );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            //插入主表
            String conFields = "xqly,xqdjr,xqdw,sfjcxq,xqrq,xqlx,xmmc,xmbh,xmxz,ygje,\n" +
                    "ysnr,zcdbjcsj,jhdbjcsj,cgy,sfbq,fj,bz,xqdh,xqbh,jcdh,\n" +
                    "htdh,xqfl,cgfs,pbfs,pid,bmid,fbid,nd,xmxzid,xqdwid,\n" +
                    "xqdwmc,xmid,cgqx";
            String sql = "select " + conFields + " from " + cgxqTable + " where id=?";
            rs.executeQuery( sql, billid );
            if (rs.next()) {
                String xqly = Util.null2String( rs.getString( "xqly" ) );//需求来源
                String xqdjr = Util.null2String( rs.getString( "xqdjr" ) );//需求对接人
                String xqdw = Util.null2String( rs.getString( "xqdw" ) );//需求单位
                String sfjcxq = Util.null2String( rs.getString( "sfjcxq" ) );//是否集采需求
                String xqrq = Util.null2String( rs.getString( "xqrq" ) );//需求日期
                String xqlx = Util.null2String( rs.getString( "xqlx" ) );//需求类型
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                String xmbh = Util.null2String( rs.getString( "xmbh" ) );//项目编号
                String ygje = Util.null2String( rs.getString( "ygje" ) );//预估金额
                String ysnr = Util.null2String( rs.getString( "ysnr" ) );//运输内容
                String zcdbjcsj = Util.null2String( rs.getString( "zcdbjcsj" ) );//最迟定标决策时间
                String jhdbjcsj = Util.null2String( rs.getString( "jhdbjcsj" ) );//计划定标决策时间
                String cgy = Util.null2String( rs.getString( "cgy" ) );//采购员
                String sfbq = Util.null2String( rs.getString( "sfbq" ) );//是否标前
                String fj = Util.null2String( rs.getString( "fj" ) );//附件
                String bz = Util.null2String( rs.getString( "bz" ) );//备注
                String xqdh = Util.null2String( rs.getString( "xqdh" ) );//需求单号
                String jcdh = Util.null2String( rs.getString( "jcdh" ) );//决策单号
                String htdh = Util.null2String( rs.getString( "htdh" ) );//合同单号
                String fplx = Util.null2String( rs.getString( "fplx" ) );//分配类型
                String xqfl = Util.null2String( rs.getString( "xqfl" ) );//需求分类
                String cgfs = Util.null2String( rs.getString( "cgfs" ) );//采购方式
                String pbfs = Util.null2String( rs.getString( "pbfs" ) );//评标方式
                String xqbh = Util.null2String( rs.getString( "xqbh" ) );//需求包号
                String pid = Util.null2String( rs.getString( "pid" ) );//PID
                String bmid = Util.null2String( rs.getString( "bmid" ) );//部门ID
                String fbid = Util.null2String( rs.getString( "fbid" ) );//分部ID
                String xmxz = Util.null2String( rs.getString( "xmxz" ) );//项目性质
                String nd = Util.null2String( rs.getString( "nd" ) );//年度
                String xmxzid = Util.null2String( rs.getString( "xmxzid" ) );//项目性质ID
                String xqdwid = Util.null2String( rs.getString( "xqdwid" ) );//需求单位ID
                String xqdwmc = Util.null2String( rs.getString( "xqdwmc" ) );//需求单位名称
                String xmid = Util.null2String( rs.getString( "xmid" ) );//项目ID
                String cgqx = Util.null2String( rs.getString( "cgqx" ) );//采购权限
                String rwzt = "0";//任务状态
                String cfdid = "";
                String formmodeid = GenUtil.getFormmodeId( cglx );
                String modedatacreatertype = "0";
                String modedatacreater = userid;
                String modedatacreatedate = DateUtil.getCurrentDate();
                String fullDate = DateUtil.getFullDate();
                String modedatacreatetime = fullDate.substring( 11, 19 );
                String fields = conFields + ",rwzt,rwbh,xqdid,cfdid,cglx," +
                        "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime";
                String values = "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?)";
                String sql1 = "insert into " + cgrwTable + " (" + fields + ") " + values;
                rs.writeLog( sql1 );
                Object[] params = {xqly, xqdjr, xqdw, sfjcxq, xqrq, xqlx, xmmc, xmbh, xmxz, ygje,
                        ysnr, zcdbjcsj, jhdbjcsj, cgy, sfbq, fj, bz, xqdh, xqbh, jcdh,
                        htdh, xqfl, cgfs, pbfs, pid, bmid, fbid, nd, xmxzid, xqdwid,
                        xqdwmc, xmid, cgqx, rwzt, rwbh, billid, cfdid, cglx,
                        formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime};
                if (rs.executeUpdate( sql1, params )) {
                    //插入明细表
                    String mainid = GenUtil.getRwbh2Id( rwbh, cglx );
                    GenUtil.getNewModeRight( cgy, formmodeid, mainid );
                    String comFieldDt1 = "hwmc,ggxh,dw,sl,zcl,ztj,qydd,dddd,qyrq,dhrq,ysfs,cgsl,sysl";
                    String sql2 = "select id," + comFieldDt1 + " from " + cgxqTable + "_dt1 where mainid=? and nvl(cfbj,0)=0";
                    rs1.executeQuery( sql2, billid );
                    int counts = rs1.getColCounts();
                    int count=0;
                    while (rs1.next()) {
                        String id = Util.null2String( rs1.getString( "id" ) );//物料名称
                        String hwmc = Util.null2String( rs1.getString( "hwmc" ) );//货物名称
                        String ggxh = Util.null2String( rs1.getString( "ggxh" ) );//规格型号
                        String dw = Util.null2String( rs1.getString( "dw" ) );//单位
                        String sl = Util.null2String( rs1.getString( "sl" ) );//数量
                        String zcl = Util.null2String( rs1.getString( "zcl" ) );//总重量
                        String ztj = Util.null2String( rs1.getString( "ztj" ) );//总体积
                        String qydd = Util.null2String( rs1.getString( "qydd" ) );//起运地点
                        String dddd = Util.null2String( rs1.getString( "dddd" ) );//到达地点
                        String qyrq = Util.null2String( rs1.getString( "qyrq" ) );//起运日期
                        String dhrq = Util.null2String( rs1.getString( "dhrq" ) );//到货日期
                        String ysfs = Util.null2String( rs1.getString( "ysfs" ) );//运输方式
                        String cgsl = Util.null2String( rs1.getString( "cgsl" ) );//采购数量
                        String sysl = Util.null2String( rs1.getString( "sysl" ) );//剩余数量
                        String sql3 = "insert into " + cgrwTable + "_dt1(" +
                                "mainid," + comFieldDt1 + ",xqmxid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, hwmc, ggxh, dw, sl, zcl, ztj, qydd, dddd, qyrq,
                                dhrq, ysfs, cgsl, sysl, id};
                        if(rs1.executeUpdate( sql3, params1 )){
                            //更新物料采购需求池的勾选拆分
                            rs1.executeUpdate( "update " + cgxqTable + "_dt1 set cfbj=1 where id=?", id );
                            count++;
                        }
                      if((counts-count)>0){
                          flag = false;
                      }
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return flag;
    }

    //服务采购需求池数据插入到服务采购任务池
    public static boolean fwneedTofwtaskPool(String userid, String billid) {
        boolean flag = true;
        BaseBean baseBean = new BaseBean();
        RecordSet rs = new RecordSet();
        baseBean.writeLog( "fwneedTofwtaskPool-----------------" + billid );
        try {
            String cglx = "4";
            RecordSet rs1 = new RecordSet();
            String rwbh = GenUtil.generTaskCode( cglx );//任务编号
            String cgxqTable = GenUtil.getCgxqTableType( cglx );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            //插入主表
            String comFields = "xqly,xqdjr,xqdw,sfjcxq,xqrq,xqlx,xmmc,xmbh,ygje,fwlb,\n" +
                    "zcdbjcsj,jhdbjcsj,cgy,sfbq,fj,bz,xqdh,jcdh,htdh,xqfl,\n" +
                    "cgfs,pbfs,xmxz,bmid,fbid,pid,fwnr,xqbh,nd,xmxzid,\n" +
                    "xqdwid,xqdwmc,xmid,cgqx";
            String sql = "select " + comFields + " from " + cgxqTable + " where id=?";
            rs.executeQuery( sql, billid );
            if (rs.next()) {
                String xqly = Util.null2String( rs.getString( "xqly" ) );//需求来源
                String xqdjr = Util.null2String( rs.getString( "xqdjr" ) );//需求对接人
                String xqdw = Util.null2String( rs.getString( "xqdw" ) );//需求单位
                String sfjcxq = Util.null2String( rs.getString( "sfjcxq" ) );//是否集采需求
                String xqrq = Util.null2String( rs.getString( "xqrq" ) );//需求日期
                String xqlx = Util.null2String( rs.getString( "xqlx" ) );//需求类型
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                String xmbh = Util.null2String( rs.getString( "xmbh" ) );//项目编号
                String ygje = Util.null2String( rs.getString( "ygje" ) );//预估金额
                String zcdbjcsj = Util.null2String( rs.getString( "zcdbjcsj" ) );//最迟定标决策时间
                String jhdbjcsj = Util.null2String( rs.getString( "jhdbjcsj" ) );//计划定标决策时间
                String cgy = Util.null2String( rs.getString( "cgy" ) );//采购员
                String sfbq = Util.null2String( rs.getString( "sfbq" ) );//是否标前
                String fj = Util.null2String( rs.getString( "fj" ) );//附件
                String bz = Util.null2String( rs.getString( "bz" ) );//备注
                String xqdh = Util.null2String( rs.getString( "xqdh" ) );//需求单号
                String jcdh = Util.null2String( rs.getString( "jcdh" ) );//决策单号
                String htdh = Util.null2String( rs.getString( "htdh" ) );//合同单号
                String xqfl = Util.null2String( rs.getString( "xqfl" ) );//需求分类
                String cgfs = Util.null2String( rs.getString( "cgfs" ) );//采购方式
                String pbfs = Util.null2String( rs.getString( "pbfs" ) );//评标方式
                String xqbh = Util.null2String( rs.getString( "xqbh" ) );//需求包号
                String fwlb = Util.null2String( rs.getString( "fwlb" ) );//服务类别
                String bmid = Util.null2String( rs.getString( "bmid" ) );//部门ID
                String fbid = Util.null2String( rs.getString( "fbid" ) );//分部ID
                String pid = Util.null2String( rs.getString( "pid" ) );//PID
                String fwnr = Util.null2String( rs.getString( "fwnr" ) );//服务内容
                String xmxz = Util.null2String( rs.getString( "xmxz" ) );//项目性质
                String nd = Util.null2String( rs.getString( "nd" ) );//年度
                String xmxzid = Util.null2String( rs.getString( "xmxzid" ) );//项目性质ID
                String xqdwid = Util.null2String( rs.getString( "xqdwid" ) );//需求单位ID
                String xqdwmc = Util.null2String( rs.getString( "xqdwmc" ) );//需求单位名称
                String xmid = Util.null2String( rs.getString( "xmid" ) );//项目ID
                String cgqx = Util.null2String( rs.getString( "cgqx" ) );//采购权限
                String rwzt = "0";//任务状态
                String cfdid = "";
                String formmodeid = GenUtil.getFormmodeId( cglx );
                String modedatacreatertype = "0";
                String modedatacreater = userid;
                String modedatacreatedate = DateUtil.getCurrentDate();
                String fullDate = DateUtil.getFullDate();
                String modedatacreatetime = fullDate.substring( 11, 19 );
                String fields = comFields + ",rwzt,cfdid,rwbh,xqdid,cglx," +
                        "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime";
                String values = "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                        "?,?,?,?)";
                String sql1 = "insert into " + cgrwTable + " (" + fields + ") " + values;
                rs.writeLog( sql1 );
                Object[] params = {xqly, xqdjr, xqdw, sfjcxq, xqrq, xqlx, xmmc, xmbh, ygje, fwlb,
                        zcdbjcsj, jhdbjcsj, cgy, sfbq, fj, bz, xqdh, jcdh, htdh, xqfl,
                        cgfs, pbfs, xmxz, bmid, fbid, pid, fwnr, xqbh, nd, xmxzid,
                        xqdwid, xqdwmc, xmid, cgqx, rwzt, cfdid, rwbh, billid, cglx,
                        formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime};
                if (rs.executeUpdate( sql1, params )) {
                    //插入明细表
                    String comFieldDt1 = "fwnr,fwyq,dw,sl,zlyq,ksrq,jsrq,cgsl,sysl";
                    String mainid = GenUtil.getRwbh2Id( rwbh, cglx );
                    GenUtil.getNewModeRight( cgy, formmodeid, mainid );
                    String sql2 = "select id," + comFieldDt1 + " from " + cgxqTable + "_dt1 where mainid=? and nvl(cfbj,0)=0";
                    rs1.executeQuery( sql2, billid );
                    int counts = rs1.getColCounts();
                    int count = 0;
                    while (rs1.next()) {
                        String id = Util.null2String( rs1.getString( "id" ) );//物料名称
                        String fwnr1 = Util.null2String( rs1.getString( "fwnr" ) );//服务内容
                        String fwyq = Util.null2String( rs1.getString( "fwyq" ) );//服务要求
                        String dw = Util.null2String( rs1.getString( "dw" ) );//单位
                        String sl = Util.null2String( rs1.getString( "sl" ) );//数量
                        String zlyq = Util.null2String( rs1.getString( "zlyq" ) );//资料要求
                        String ksrq = Util.null2String( rs1.getString( "ksrq" ) );//开始日期
                        String jsrq = Util.null2String( rs1.getString( "jsrq" ) );//结束日期
                        String cgsl = Util.null2String( rs1.getString( "cgsl" ) );//采购数量
                        String sysl = Util.null2String( rs1.getString( "sysl" ) );//剩余数量
                        String sql3 = "insert into " + cgrwTable + "_dt1(mainid," + comFieldDt1 + ",xqmxid) " +
                                "values (?,?,?,?,?,?,?,?,?,?,?)";
                        Object[] params1 = {mainid, fwnr1, fwyq, dw, sl, zlyq, ksrq, jsrq, cgsl, sysl, id};
                        if(rs1.executeUpdate( sql3, params1 )){
                            count++;
                            //更新物料采购需求池的勾选拆分
                            rs1.executeUpdate( "update " + cgxqTable + "_dt1 set cfbj=1 where id=?", id );
                        }
                    }
                    if(counts-count>0){
                        flag = false;
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return flag;
    }

    //参数日期减去当前日期获取天数
    public static long getDays(String date) {
        long days = 0L;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
            Date d1 = sdf.parse( date );
            long ts1 = d1.getTime();
            Date d2 = sdf.parse( DateUtil.getCurrentDate() );
            long ts2 = d2.getTime();
            days = (ts1 - ts2) / (1000 * 60 * 60 * 24);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return days;
    }
}
